<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text">
    <button>点击</button>
    <h1></h1>
    <script>
        var ipt = document.querySelector('input')
        var btn = document.querySelector('button')
        var hh = document.querySelector('h1')
        btn.addEventListener('click', function () {
            if (ipt.value.trim() == '') {
                alert('内容不能为空')
            }
            hh.innerHTML = ipt.value.trim()
        })
    </script>
</body>

</html>